package com.fenghuajueli.module_user.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;

import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.fenghuajueli.libbasecoreui.mvp.BaseActivity;
import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModel;
import com.fenghuajueli.libbasecoreui.viewmodel.data.LoadingData;

/**
 * 用户模块的activity基类，实现基础的toast和dialog的显示和隐藏，viewmodel
 */
public abstract class UserViewModelBaseActivity extends BaseActivity {

    /**
     * 注册通用的ui改变监听使用
     */
    protected BaseViewModel baseViewModel;

    public abstract BaseViewModel setBaseViewModel();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initStatusBarColor();

        baseViewModel = setBaseViewModel();

        if (baseViewModel != null) {
            baseViewModel.loadingViewData.observe(this, data -> {
                switch (data.getStatus()) {
                    case LoadingData.LOADING_START:
                        showLoadingDialog(data.getLoadingTips());
                        break;
                    case LoadingData.LOADING_STOP:
                        hideLoadingDialog();
                        break;
                }
            });

            baseViewModel.finishActivityData.observe(this, integer -> finish());
        }
    }


    protected void initStatusBarColor() {
        BarUtils.setStatusBarColor(this, ColorUtils.getColor(com.fenghuajueli.module_user.R.color.defaultStatusBarColor));
        BarUtils.setStatusBarLightMode(this, AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO);
        BarUtils.setNavBarLightMode(this, AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO);
    }


}
